#ifndef PORT_COMM_H_
#define PORT_COMM_H_

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>

#include <string.h>

#define SUCCESS_PORT 1
#define FAILURE_PORT 0

class PortComm{

 public:
  // Enum Type
  enum PortCommType {SERVER, CLIENT};

  // Constructor
  PortComm(const char* host, int portno, PortCommType type);

  // Deconstructor
  ~PortComm(void);

  // Methods
  bool isValid(void);
  int write_port(unsigned char* buffer, int length);
  int read_port(unsigned char **buffer, int* length);

  // FIXME adding listeing accpets using select

 protected:
  // Members
  PortCommType comm_type;
  int sockfd;
  int cliefd;
  bool valid;

  struct sockaddr_in serv_addr, cli_addr;
  struct hostent *server;
  socklen_t clilen;

  // Methods
  int initHost(int portno);
  int initClie(const char* host, int portno);
  
};
#endif
